<?php
/**
 *  删除玩家邮件,删除已读没附件的邮件与已读已领取附件的邮件
 */

class DelEmail extends APIBase {
	public $tag = "DelEmail";
	public $isLogin = true;
	
	public function before() {
		$this->initMysql();
		$this->inithttp();
		$this->initCacheRedis();
		return true;
	}
			
	public function logic() {
		$eid = $this->param['eid'];//邮件id
	    $uid = $this->uid;
		$emailinfo = $this->cache_redis->hGetAll('hemailbyuser:'.$uid.':'.$eid);
		$data = array();
		if(!empty($emailinfo)){
			if($emailinfo['is_read']!=9){
			    if($emailinfo['is_read']==1){
				    $hmg = $this->cache_redis->hMget('hmg:'.$emailinfo['mid'],array('rid'));
			        //判断邮件是否有附件
			        if($hmg['rid']==''){
				        //若没附件,修改邮件状态
				        $this->cache_redis->hMset('hemailbyuser:'.$uid.':'.$eid,array('is_read'=>9));
					    $this->returnData('success');
			        }else{
				        //若有附件,则判断是否已领取
				        if($emailinfo['is_receive']==1){//已领取,修改邮件状态
						    $this->cache_redis->hMset('hemailbyuser:'.$uid.':'.$eid,array('is_read'=>9));
						    $this->returnData('success');
					    }else{
						    $this->returnError(303,'尚未领取,删除失败');
					    }
			        }
			    }else{
				    $this->returnError(302,'尚未读,删除失败');
			    }
			}
		}else{
			$this->returnError(301,'无效参数！！');
		}
	}

	public function after() {
		$this->deinitDataRedis();
		$this->deinitMysql();
	}
}

?>
